// 处理与用户相关的接口

// 手动导入配置号的axios
import axios from '@/utils/request'

// 用户头像
export const uploadPhoto = function (fd) {
  return axios({
    method: 'patch',
    url: '/v1_0/user/photo',
    data: fd
  })
}

// 编辑用户信息
export const editUser = function ({ name, gender, birthday, intro }) {
  return axios({
    method: 'patch',
    url: '/v1_0/user/profile',
    data: {
      name, gender, birthday, intro
    }
  })
}

// 0.导出 查询个人用户接口
export const getProfile = function () {
  return axios({
    url: '/v1_0/user/profile'
  })
}

// 0.导出更新token接口
export const getNewToken = function (refreshToken) {
  console.log('refreshToken->', refreshToken)
  return axios({
    url: '/v1_0/authorizations',
    method: 'put',
    headers: {
      Authorization: `Bearer ${refreshToken}`
    }
  })
}

// 按需导出 不同的接口请求方法
// 1.导出登录接口
export const login = function (mobile, code) {
  // 返回 axiox 创建的 Promise对象
  return axios({
    method: 'post',
    url: '/v1_0/authorizations',
    data: {
      mobile,
      code
    }
  })
}
// 2.导出发送验证码接口
export const sendSMS = function (mobile) {
  return axios({
    method: 'get',
    url: `/v1_0/sms/codes/${mobile}`
  })
}

// 3.获取用户数据
export const getUserInfo = function () {
  return axios({
    method: 'get',
    url: '/v1_0/user'
    // headers: { Authorization: `Bearer ${userToken}` }
  })
}

// 4.获取用户频道列表数据
export const getUserChannels = function () {
  return axios({
    method: 'get',
    url: '/v1_0/user/channels'
  })
}

// 5.添加关注用户
export const addFollow = function (targetid) {
  return axios({
    url: '/v1_0/user/followings',
    method: 'post',
    data: {
      target: targetid
    }
  })
}

// 6.取消关注用户
export const delFollow = function (targetid) {
  return axios({
    url: `/v1_0/user/followings/${targetid}`,
    method: 'delete'
  })
}

// 6.收藏文章
export const addCollect = function (targetid) {
  return axios({
    url: '/v1_0/article/collections',
    method: 'post',
    data: {
      target: targetid
    }
  })
}

// 7.取消收藏
export const delCollect = function (targetid) {
  return axios({
    url: `/v1_0/article/collections/${targetid}`,
    method: 'delete'
  })
}

// 8.获取用户收藏列表
export const getUserCollect = function (params) {
  return axios({
    url: '/v1_0/article/collections',
    method: 'get',
    params
  })
}

// 9.获取用户阅读历史
export const getUserHistories = function (params) {
  return axios({
    url: '/v1_0/user/histories',
    method: 'get',
    params
  })
}
